<#include "/includes/vars.inc"> 
<@pp.dropOutputFile />
<#assign fileName = "${javaDir}${packageDir}/service/support/AbstractService.java">
<#if !pp.outputFileExists(fileName)>
	<@pp.changeOutputFile name="${fileName}" />

package ${project.@rootPackage}.service.support;

import ${project.@rootPackage}.dao.support.GenericDao;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;

/**
 * AbstractService class
 * <#if project.@author[0]??>@author ${project.@author}</#if>
 */
public abstract class AbstractService<T> {
    
    public abstract GenericDao<T> getDao();
    
  
    public List<T> findAll(){
        return getDao().findAll();
    }

    public T findById(Long id){
        return getDao().findById(id);
    }
    
    @Transactional
    public boolean delete(T entity){
        return getDao().delete(entity);
    }
    
    @Transactional
    public boolean update(T entity){
        return getDao().update(entity);
    }
    
    @Transactional
    public boolean create(T entity){
        return getDao().create(entity);
    }

    @Transactional
    public boolean create(Iterable<T>  entities) {
        for (T entity : entities) {
            if (!getDao().create(entity)) {
                return false;
            }
        }
        return true;
    }

    @Transactional
    public boolean delete(Iterable<T>  entities) {
        for (T entity : entities) {
            if (!getDao().delete(entity)) {
                return false;
            }
        }
        return true;
    }

    @Transactional
    public boolean update(Iterable<T>  entities) {
        for (T entity : entities) {
            if (!getDao().update(entity)) {
                return false;
            }
        }
        return true;
    }
      
}
</#if>